/*******************************************************************************
 * Copyright (c) 2009 L.Carbonnaux.
 *******************************************************************************/

package org.lcx.taskvision.ui.editor;

import org.eclipse.mylyn.tasks.ui.ITasksUiConstants;
import org.eclipse.mylyn.tasks.ui.TasksUiUtil;
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPageFactory;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditorInput;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.forms.editor.FormPage;
import org.lcx.taskvision.core.TaskVisionCorePlugin;
import org.lcx.taskvision.ui.TaskVisionImages;

/**
 * @author Laurent Carbonnaux
 */
public class TaskVisionTaskEditorPageFactory extends AbstractTaskEditorPageFactory {

	protected String connectorKind = TaskVisionCorePlugin.CONNECTOR_KIND;

	@Override
	public boolean canCreatePageFor(TaskEditorInput input) {
		if (input.getTask().getConnectorKind().equals(connectorKind)) {
			return true;
		} else if (TasksUiUtil.isOutgoingNewTask(input.getTask(), connectorKind)) {
			return true;
		}
		return false;
	}

	@Override
	public FormPage createPage(TaskEditor parentEditor) {
		return new TaskVisionTaskEditorPage(parentEditor, connectorKind);
	}

	@Override
	public String[] getConflictingIds(TaskEditorInput input) {
		if (!input.getTask().getConnectorKind().equals(connectorKind)) {
			return new String[] { ITasksUiConstants.ID_PAGE_PLANNING };
		}
		return null;
	}

	@Override
	public Image getPageImage() {
		return TaskVisionImages.getImage(TaskVisionImages.LOGO);
	}

	@Override
	public String getPageText() {
		return Messages.ScrumVisionTaskEditorPageFactory_title;
	}

	@Override
	public int getPriority() {
		return PRIORITY_TASK;
	}

}
